#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
using namespace std;
string reverseWords(string&input){
	istringstream iss(input);
	string word;
	vector<string>reversedWord;
	while(iss>>word){
		reverse(word.begin(),word.end());
		reversedWord.push_back(word);
	}
	string result;
	for(size_t i=0;i < reversedWord.size();i++){
		 if (i > 0) result += " ";
        result += reversedWord[i];
	}
	return result;
}

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	int N;
	cin>>N;
	cin.ignore() ;
	for(int i=0;i<N;i++){
		string line;
		getline(cin,line);
		cout<<reverseWords(line)<<endl;
	}
	return 0;
}